<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 

/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of MessageCode
 *
 * @author nelfrits
 */
class applicationsetup {
    //put your code here
    
    var $CI;
    public function __construct(){
        $this->CI =& get_instance();
        $this->CI->load->model('system_model');

        $this->UserInfo();
        if(!$this->CI->session->userdata('site_parameter')){
			$this->SetUserData('site_parameter');
		}
        if(!$this->CI->session->userdata('site_page')){
			$this->SetUserData('site_page');
		}
        
        
    }

    function SetUserData($session_name)
    {
        $params = null;
        $alluserdata  = $this->CI->session->all_userdata();
        
        if(empty($alluserdata[$session_name])){
            switch ($session_name) {
                case 'site_parameter':
                    $params = $this->GetAllParameter();
                    break;
                //case 'site_messagecode' :
                //    $params = $this->GetAllMessageCode();
                //    break;
                case 'site_page' :
                    $params = $this->GetAccesiblePages(0);
                    break;
                default:
                    break;
            }
         
            $this->CI->session->set_userdata($session_name, $params);
        }
        
    }

    function UserInfo(){
		$userinfo = array(
            'UserId'=>0,
            'UserLogin'=>'Anonymous',
            'TimeZone'=>date_default_timezone_get()
        );
        if(!$this->CI->session->userdata('UserInfo')){
			$this->CI->session->set_userdata('UserInfo', $userinfo);
		}
        
    }

    function GetAllParameter(){
        return $this->CI->system_model->get_parameters();
    }

    function GetParameterById($id){
        
    }

    function GetAllMessageCode(){
        return $this->CI->system_model->get_messagecode();
    }
    
    function GetMessageCodeById($id){
        return $this->CI->system_model->get_messagecode($id);
    }

    function GetAccesiblePages($userid){
		return $this->CI->system_model->get_defaultpage($userid);
    }

    function GetSecurePages(){
        $defaultpages = $this->CI->session->userdata('site_page');
        //$page = array_combine($defaultpages, $this->CI->system_model->get_securepages($this->CI->session->userdata('site_page')))
        
    }
    
    
}

/* End of file applicationsetup.php */
/* Location: ./application/libraries/applicationsetup.php */
